class PriorityQueue {
    constructor () {
        this.items = []
    }

    enqueue (element, priority) {
        const queueEle = new QueueElement(element, priority)
        const len = this.items.length
        if (len) {
            let hasEnqueue = false
            for (let i = 0; i < len; i++) {
                if (priority < this.items[i].priority) {
                    this.items.splice(i, 0, queueEle)
                    hasEnqueue = true
                    break
                }
            }
            if (!hasEnqueue) {
                this.items.push(queueEle)
            }
        } else {
            this.items.push(queueEle)
        }
    }

    dequeue () {
        this.items.shift()
    }

    front () {
        return this.items[0]
    }

    size () {
        return this.items.length
    }

    isEmpty () {
        return !this.items.length
    }
}

class QueueElement {
    constructor (element, priority) {
        this.element = element
        this.priority = priority
    }
}

export default PriorityQueue
